<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" 
           uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>菜谱</title>
<link rel="stylesheet" type="text/css"
	href=${pageContext.servletContext.contextPath}/themes/bootstrap/easyui.css>
<link rel="stylesheet" type="text/css"
	href=${pageContext.servletContext.contextPath}/themes/icon.css>
<link rel="stylesheet" type="text/css"
	href=${pageContext.servletContext.contextPath}/themes/color.css>
<script type="text/javascript"
	src=${pageContext.servletContext.contextPath}/js/jquery.min.js></script>
<script type="text/javascript"
	src=${pageContext.servletContext.contextPath}/js/jquery.easyui.min.js></script>
<script type="text/javascript"
	src=${pageContext.servletContext.contextPath}/js/easyui-lang-zh_CN.js></script>
</head>
<script type="text/javascript">
	$(function(){
		//did
		var id = 0;
		//oid
		var id1 = 0;
		$.ajax({
			url:'${pageContext.servletContext.contextPath}/selectsuqiu',
			type:"post",
			dataType:"json",
		})
		//加菜时的窗口
		$('#add').window({    
		    width:600,    
		    height:400,    
		    modal:true,
		    title:"加菜窗口",
		}); 
		$('#add').window('close');
		
		//点菜单数据表格
		$('#dg').datagrid({    
			 url:'${pageContext.servletContext.contextPath}/loaddesk', 
			    pagination:true,
			    striped:true,
			    loadMsg:'正在加载',
			    rownumbers:true,
			    pageSize:5,
				pageList:[5,10,15,20],
			    columns:[[    
			        {field:'ck',checkbox:true,width:100},    
			        {field:'oid',title:'菜单id',width:100,hidden:true},    
			        {field:'did',title:'桌号id',width:100,align:'right'}, 
			        {field:'foodlist',title:'所点菜品id',width:100,align:'right'},    
			        {field:'fstate',title:'菜单状态',width:100,align:'right'},    
			        {field:'wid',title:'点菜员id',width:100,align:'right'},    
			        {field:'fnum',title:'人数',width:100,align:'right'},    
			        {field:'ftime',title:'提交时间',width:100,align:'right'},    
			    ]],    
			    toolbar: [{
					iconCls: 'icon-add',
					text:'新点菜',
					width:200,
					handler: function(){
						var num = $('#dg').datagrid('getSelections');
						if(num.length!=1){
							$.messager.show({
								title:'我的消息',
								msg:'请选择一条需要加菜的记录！！！',
								timeout:2000,
								showType:'slide'
							});
							
						}else{
							$.each(num,function(i,n){
								id = n.did;
								ids = n.oid;
							})
							$('#add').window('open');
						}
					}
				}]
		});
		//加菜数据表格
		$('#dd').datagrid({    
		    url:'${pageContext.servletContext.contextPath}/loadfood', 
		    pagination:true,
		    striped:true,
		    loadMsg:'正在加载',
		    rownumbers:true,
		    pageSize:5,
			pageList:[5,10,15,20],
		    columns:[[    
		        {field:'ck',checkbox:true,width:100},    
		        {field:'fid',title:'菜品id',width:100,align:'right'},    
		        {field:'fname',title:'菜名',width:100,align:'right'}, 
		    ]]
		})
		//点击增加菜品确定时
		$("#addqd").click(function(){
			var num = $('#dd').datagrid('getSelections');
			$.ajax({
					url:'${pageContext.servletContext.contextPath}/addcaipin',
					type:"post",
					dataType:"json",
					async:true,
					data:{
						'data':JSON.stringify(num),
						'did':id,
						'oid':id1
						},
						success: function(data){    
				            var da = data.flag;
				            if (da==true){    
				            	$('#dg').datagrid('reload');
				            	$.messager.show({
									title:'我的消息',
									msg:'点菜成功！',
									timeout:2000,
									showType:'slide'
								})
				            }
						}
				})
				alert("确认加菜?",function(){
	        		$('#add').window('close');
	        		
	        	});
		})
	})
</script>
<body>
	<!-- 数据表格 -->
	<table id="dg"></table> 
	<!-- 加菜的窗口 --> 
	<div id="add" align="center">
		<form id="fadd" method="post">
			<table id="dd"></table>
			<br>
			<button id="addqd" class="easyui-linkbutton">确定</button>
		</form> 
	</div>  
</body>
</html>